﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.ServiceProcess;
using System.IO;

namespace WCF_AutoUpdates_Services
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public static bool IsLoadStart
        {
            get;
            private set;
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Length > 0)
            {
                if (e.Args.Where((s) => s.ToLower() == "-autostart").Count() > 0)
                {
                    IsLoadStart = true;
                }
                else
                {
                    IsLoadStart = false;
                }
            }

            //设置当前路径，否则其它地方使用出错
            Environment.CurrentDirectory = new FileInfo(this.GetType().Assembly.Location).DirectoryName;

            //可以捕获操作，这通常在用户空间运行
            if (Environment.UserInteractive)
            {
                new MainWindow().ShowDialog();
            }
            //以服务运行，或者由其它的在session0中启动
            else
            {
                ServiceBase.Run(new WinService.WinahrimanAutoUpdate());
            }
            this.Shutdown();
        }
    }
}
